<template>
  <view class="contain">
    <view class="wrap-header"
          :style="{ 'padding-top': top + 'px','background-image': bgImage }">
      <view class="flex f-j-e h-44 padding-lr5">
        <!-- <view class="flex f-a-c f-j-c van-icon van-icon-qr f20-size t-color-3 padding-lr5"><text
            class="f12-size">{{i18n['会员码']}}</text></view> -->
        <view @click="go('/pagesA/setting/index')"
              class="flex f-a-c f-j-c van-icon van-icon-setting-o f20-size padding-lr5"></view>
        <!-- <view @click="go('/pages/chat/index')" class="flex f-a-c f-j-c van-icon van-icon-chat-o f20-size padding-lr5"></view> -->
        <xcx-header></xcx-header>
      </view>
      <view class="padding-lr15 flex">
        <view v-if="user != ''" @click="updateImg" class="w-60 h-60 b-radius  bg-img margin-r12"
              :style="user.headImg | bgimg(300)+''"></view>
        <view v-else class="w-60 h-60 b-radius  bg-img margin-r12" :style="defaultImg | bgimg(300)+''"></view>
        <view class="flex f-c f-a-s">
          <view v-if="user == ''" @click="toShowPhoneLogin" class="f22-size">{{ i18n['登录'] }} /
            {{ i18n['注册'] }}
          </view>
          <!--          <view v-if="user == ''" @click="go('/pageB/passport/login')" class="f22-size">{{ i18n['登录'] }} /-->
          <!--            {{ i18n['注册'] }}-->
          <!--          </view>-->
          <view v-if="user != ''" class="f22-size" @click="updateNickname">{{ user.nickname }}</view>
          <view class="f10-size padding-lr6 b-radius-2 h-16 t-color-w bg-color-linear-r margin-t6">
            {{ i18n['Hi，欢迎登录'] }}
          </view>
          <view>
            <view class="f10-size padding-lr6 b-radius-2 h-16 t-color-w bg-color-linear-g margin-t6"
                  v-if="isShowMerchantAuthentication" @click="openAuthShop">
              开始认证
            </view>
          </view>


          <view class="f10-size padding-lr6 b-radius-2 h-16 t-color-w bg-color-linear-r margin-t6"
                v-if="isShowSuccessAuth">
            已经商家认证
          </view>
        </view>

      </view>
      <view class="flex margin-t15">
        <view @click="go('/pagesB/user/like')" class="flex flex-1 f-c f-a-c f-j-c">
          <view class="flex f-a-c f-j-c van-icon van-icon-star-o f24-size margin-b4"></view>
          <text class="f12-size">{{ i18n['收藏夹'] }}</text>
        </view>
        <view @click="openAssociationShopInfo" class="flex flex-1 f-c f-a-c f-j-c">
          <view class="flex f-a-c f-j-c van-icon van-icon-cluster-o f24-size margin-b4"></view>
          <text class="f12-size">{{ '关联商家' }}</text>
        </view>
        <view @click="go('/pagesB/user/history')" class="flex flex-1 f-c f-a-c f-j-c">
          <view class="flex f-a-c f-j-c van-icon van-icon-clock-o f24-size margin-b4"></view>
          <text class="f12-size">{{ i18n['足迹'] }}</text>
        </view>
        <view @click="go('/pagesA/find/trendsDownloadNumApply')" class="flex flex-1 f-c f-a-c f-j-c">
          <view class="flex f-a-c f-j-c van-icon van-icon-sign f24-size margin-b4"></view>
          <text class="f12-size margin-t6">{{ '申请记录' }}</text>
        </view>
      </view>
      <view class="padding-20"></view>
      <view class="wrap-coupon-btn flex b-radius-5 bg-color-w padding-10">
        <view @click="checkMyAuthInfo()" class="flex flex-1 f-a-c f-j-s padding-lr2 wrap-coupon-btn-left margin-r10">
          <view class="flex f-c">
            <text class="f12-size f-w-b">认证信息</text>
            <view class="flex f-a-c">
              <text class="f10-size t-color-y margin-r4">我的媒体平台</text>
              <text class="flex f-a-c van-icon van-icon-arrow t-color-y f12-size"></text>
            </view>
          </view>
<!--          <image src="../../static/images/user_coupon_icon.png" mode="widthFix" class="w-36 margin-r12">-->
<!--          </image>-->
        </view>
        <view @click="gotToDownloadNumApply" class="flex flex-1 f-a-c f-j-s padding-lr2">
          <view class="flex f-c">
            <text class="f12-size f-w-b">下载申请</text>
            <view class="flex f-a-c">
              <text class="f10-size t-color-y margin-r4">申请下载次数</text>
              <text class="flex f-a-c van-icon van-icon-arrow t-color-y f12-size"></text>
            </view>
          </view>
<!--          <image src="../../static/images/user_vip_icon.png" mode="widthFix" class="w-36 margin-r12"></image>-->
        </view>
      </view>
    </view>
    <view class="padding-12"></view>
    <view class="padding-lr12">

      <view class="bg-color-w b-radius-5  flex f-w margin-t12" style="padding-top: 12px;">

        <view @click="goToCredit" class="flex f-s-0 f-c btn-item">
          <view class="flex f-a-c f-j-c h-30">
            <text class="flex f-a-c f-j-c shops-icon shops-icon-qiandao f24-size"></text>
          </view>
          <view class="flex f-j-c f12-size t-color-6 margin-t2">{{ i18n['签到'] }}</view>
        </view>

        <view @click="go('/pagesB/user/advice')" class="flex f-s-0 f-c btn-item">
          <view class="flex f-a-c f-j-c h-30">
            <text class="flex f-a-c f-j-c shops-icon shops-icon-yijianfankui f28-size"></text>
          </view>
          <view class="flex f-j-c f12-size t-color-6 margin-t2">{{ i18n['反馈'] }}</view>
        </view>
        <view @click="go('/pagesB/user/help')" class="flex f-s-0 f-c btn-item">
          <view class="flex f-a-c f-j-c h-30">
            <text class="flex f-a-c f-j-c shops-icon shops-icon-bangzhu f26-size"></text>
          </view>
          <view class="flex f-j-c f12-size t-color-6 margin-t2">{{ i18n['帮助中心'] }}</view>
        </view>
        <view @click="goService(2)" class="flex f-s-0 f-c btn-item">
          <view class="flex f-a-c f-j-c h-30">
            <text class="flex f-a-c f-j-c shops-icon shops-icon-kefu f24-size"></text>
          </view>
          <view class="flex f-j-c f12-size t-color-6 margin-t2">{{ i18n['智能小蜜'] }}</view>
        </view>

        <view @click="go('/pagesA/setting/index')" class="flex f-s-0 f-c btn-item">
          <view class="flex f-a-c f-j-c h-30">
            <text class="flex f-a-c f-j-c shops-icon shops-icon-shezhi f24-size"></text>
          </view>
          <view class="flex f-j-c f12-size t-color-6 margin-t2">{{ i18n['设置'] }}</view>
        </view>

        <view @click="goToThirdAccount" class="flex f-s-0 f-c btn-item">
          <view class="flex f-a-c f-j-c h-30">
            <text class="flex f-a-c f-j-c shops-icon shops-icon-kefu f24-size"></text>
          </view>
          <view class="flex f-j-c f12-size t-color-6 margin-t2">账号管理</view>
        </view>
      </view>
      <view class="flex f-a-c f-j-c margin-t12">

        <span
            style="font-family: '微软雅黑', Arial, Helvetica, sans-serif;font-size: 20px;color: #333;text-shadow: 1px 1px #aaa;-webkit-text-stroke: 1px #666;  ">最近下载</span>
      </view>
      <view class="padding-6"></view>

      <userTrendsDownload ref="userTrendsDownload"></userTrendsDownload>
    </view>
    <notice></notice>
    <tab-bar ref="tabbar" :active="4"></tab-bar>


    <u-modal v-model="showAssociationShopInfo" title="关联商家信息">
      <u-form :model="associationShopForm" ref="uForm" style="margin: 10px" label-width="70px">
        <u-form-item label="商家名称">
          <u-input v-model="associationShopForm.name" placeholder="请输入商家名称"/>
        </u-form-item>
      </u-form>
    </u-modal>

    <toDownloadApplyModal ref="toDownloadApplyModal"></toDownloadApplyModal>

    <toUserAuth ref="toUserAuth"
                :invitMsg="invitMsg"
                :isDisabled="isDisabled"
                :invitationCode="shopAuthForm.invitationCode"
                :invitationName="shopAuthForm.bindShop"
                :invitationDate="shopAuthForm.authDate"
                :currentDoAuth="currentDoAuth" @updateAuthStatus="updateAuthStatus"></toUserAuth>

    <updateHeadNickname ref="updateHeadNickname" :memberId="user.id" :currentPage="currentPage"
                        @userIndexRefresh="userIndexRefresh"></updateHeadNickname>

    <u-popup v-model="showUpdateNickname" mode="bottom" height="130px" border-radius="20">
      <view style="margin-left: 10px;padding: 20px;">
        <view style="display: flex;">
          <view>
            <u-form-item label="昵称">
              <u-input placeholder="请输入昵称" v-model="nicknameUpdate" clearable/>
            </u-form-item>
          </view>
        </view>
      </view>
      <view style="display: flex;margin-top: 5px;margin-left: 10px">
        <u-button size="default" :custom-style="customStyle1" @click="cancel">取消</u-button>
        <u-button size="default" :custom-style="customStyle2" style="margin-left: 10px" @click="updateUserInfo">保存
        </u-button>
      </view>
    </u-popup>

    <u-popup v-model="showPhoneLogin" mode="bottom">
      <view class="phoneLoginTile">为了你的账号安全，请绑定手机号</view>
      <view @click="isAgree = !isAgree" class="flex f-a-c margin-t12">
        <view class="padding-6"></view>
        <text :class="isAgree ? 'van-icon-checked t-color-y' : 'van-icon-circle t-color-b'"
              class="flex f-a-c f-j-c van-icon  f16-size margin-r4"></text>
        <text class="margin-r4 flex f-s-0">{{ i18nLogin['已阅读并同意'] }}</text>
        <text @click="go('/pagesB/user/rules?type=1')" class="t-color-blue1 margin-r4  flex f-s-0">
          《{{ i18nLogin['用户协议'] }}》
        </text>
        <text @click="go('/pagesB/user/rules?type=2')" class="t-color-blue1  flex f-s-0">《{{ i18nLogin['隐私政策'] }}》
        </text>
      </view>
      <view class="padding-10">
        <u-button @click="getPhoneClick" type="success" :custom-style="customStyle3" v-if="!isAgree">
          授权微信手机号登录
        </u-button>
        <u-button @getphonenumber="toAuthAndLogin" open-type="getPhoneNumber" v-if="isAgree" type="success"
                  :custom-style="customStyle3">
          授权微信手机号登录
        </u-button>
        <u-button :custom-style="customStyle" @click="loginUseOtherPhone">使用其他号码登录</u-button>
        <u-button :custom-style="customStyle" @click="rejectLogin">拒绝登录</u-button>
      </view>

    </u-popup>


    <u-modal v-model="showGetOtherPhone" title="验证手机号" show-cancel-button confirm-text="登录"
             @confirm="toLoginWithOtherPhone">
      <u-form :model="formGetOtherPhone" ref="uFormPhoneLogin" style="padding: 10px">
        <view class="flex h-50 b-radius-30 bg-color-f1 margin-t8">
          <view class="flex flex-1 padding-lr12">
            <u-form-item prop="phone">
              <u-input class="f16-size" v-model="formGetOtherPhone.phone" type="tel"
                       maxlength="11" :placeholder="i18nLogin['请输入手机号码']"/>
            </u-form-item>
          </view>
        </view>

        <view class="flex h-50 b-radius-30 bg-color-f1 margin-t8">
          <view class="flex flex-1 padding-lr12">
            <u-form-item prop="sms">
              <u-input class="f16-size" v-model="formGetOtherPhone.sms" type="tel"
                       :placeholder="i18nLogin['请输入验证码']"/>
            </u-form-item>
          </view>
          <view class="padding-6">
            <phone-code :phone="formGetOtherPhone.phone" :code="formGetOtherPhone.code"
                        :sendType="4" ref="phoneCodeRef"></phone-code>
          </view>
        </view>
      </u-form>


    </u-modal>
  </view>


</template>
<style scoped>
@import url('../../static/css/user/index.css');
@import url('../../static/css/iconcolor.css');

.phoneLoginTile {
  font-size: large;
  margin-left: 13px;
  margin-top: 10px;
}
</style>
<script>
import userTrendsDownload from './userTrendsDownload.vue';
import toUserAuth from './components/toUserAuth.vue';
import toDownloadApplyModal from '../common/toDownloadApply.vue';
import updateHeadNickname from "@/pages/user/components/updateHeadNickname.vue";
import {go} from "@/utils/api";
import phoneCode from '../common/phonecode.vue';
import WXBizDataCrypt from "@/utils/WXBizDataCrypt";

const apiUrl = {
  phoneLogin: 'common/xcx/phoneLogin'
};
const shopsAPI = require('../../utils/api/shops.js').default;
const commonAPI = require('../../utils/api/common.js').default;
const API = require('../../utils/api/user.js').default;
const $ = require('../../utils/api.js');
let self;
export default {


  data() {
    return {
      formGetOtherPhone: {
        phone: "",
        code: "102938111",
        sms: ""
      },
      showGetOtherPhone: false,
      customStyle3: {
        "margin-bottom": "10px",
        "margin-top": "10px",
        "width": "95%"
      },
      customStyle: {
        "background-color": " #eee",
        "margin-bottom": "10px",
        "width": "95%"
      },
      isAgree: false,
      showPhoneLogin: false,
      nicknameUpdate: "",
      customStyle1: {
        background: '#ffa600 !important',
        color: '#fff !important',
        border: 'none !important'
      },
      customStyle2: {
        background: '#58b4a9 !important',
        color: '#fff !important',
        border: 'none !important'
      },
      showUpdateNickname: false,
      currentPage: "userIndex",
      invitMsg: "",
      isDisabled: false,

      tabsCurrent: 0,
      conListsDy: [],
      conListsKs: [],
      conListsXhs: [],
      conListsBz: [],
      conListsSph: [],

      associationShopForm: {},
      showAssociationShopInfo: false,
      rules: {
        invitationCode: [
          {
            required: true,
            message: '请输入商家会员邀请码',
            // 可以单个或者同时写两个触发验证方式
            trigger: ['change', 'blur'],
          }
        ],
      },
      rulesPhoneLogin: {
        phone: [
          {
            required: true,
            message: '手机号不能为空',
            // 可以单个或者同时写两个触发验证方式
            trigger: ['change', 'blur'],
          }
        ],
        sms: [
          {
            required: true,
            message: '验证码不能为空',
            trigger: ['change', 'blur'],
          }
        ]
      },
      shopAuthForm: {
        invitationCode: '',
        bindShop: '',
        authDate: ''
      },
      isShowSuccessAuth: false,
      isShowMerchantAuthentication: false,
      top: uni.getStorageSync('bartop') ? uni.getStorageSync('bartop') : 0,
      isIphonex: uni.getStorageSync('isIphonex') ? uni.getStorageSync('isIphonex') : false,
      list: [],
      user: {},
      account: '',
      order: '',
      defaultImg: '',
      orderList: [],
      now: 0,
      style: '',
      currentDoAuth: "",
      smsCode: "",
      session_key: "",
      phone: "",
      openid: ""
    };
  },

  onLoad: function (data) {
    self = this;
    self.getAppIdSecret()
    self.loadData()
    let config = uni.getStorageSync('config') ? uni.getStorageSync('config') : '';
    self.defaultImg = config != '' ? config.default_head_img : '';
    this.getStyle().then((res) => {
      self.style = res;
    })
  },
  onShow: function () {
    this.$nextTick(() => {
      this.$refs.tabbar.reloadHeight();
    })
  },
  methods: {
    goToCredit() {
      let isLogin = uni.getStorageSync('token') ? true : false;
      if (isLogin) {
        go('/pagesB/user/credit')
      } else {
        go('/pagesB/passport/login')
      }
    },

    goToThirdAccount() {
      let isLogin = uni.getStorageSync('token') ? true : false;
      if (isLogin) {
        go('/pagesA/thirdAccount/index')
      } else {
        go('/pagesB/passport/login')
      }

    },

    loadData() {
      const self = this;
      this.$nextTick(() => {
        this.$refs.tabbar.getChatLen();
        self.$refs.userTrendsDownload.init()
      })
      self.getUserInfo()
      self.user = uni.getStorageSync('userInfo');
      uni.stopPullDownRefresh();
    },
    toShowPhoneLogin() {
      /*#ifdef MP-WEIXIN*/
      this.isAgree = false
      this.showPhoneLogin = true
      /*#endif*/

      /*#ifdef H5*/
      $.go('/pagesB/passport/login');
      /*#endif*/

    },
    //请求获取appid和secret
    getAppIdSecret() {
      let self = this
      let postData = {}
      //授权成功后拿openid和电话去登录
      $.ajax({
        url: commonAPI.getWxConfig,
        data: postData,
        method: 'GET',
        complete(res) {
          if (res.code === 200) {
            let appId = res.data.xcxAppId
            let secret = res.data.xcxSecret
            self.goGetSessionKey(appId, secret)
          } else {
            uni.showToast({
              title: res.message,
              icon: 'none'
            });
          }
        }
      });
    },
    goGetSessionKey(appId, secret) {
      uni.login({
        provider: 'weixin',
        success: res => {
          console.log(res)
          this.js_code = res.code
          let postData = {
            appid: appId, //你的小程序的APPID
            secret: secret, //你的小程序秘钥secret,
            js_code: this.js_code, //uni.login 登录成功后的code
            grant_type: 'authorization_code' //此处为固定值
          }
          //授权成功后拿openid和电话去登录
          $.ajax({
            url: commonAPI.jscode2session,
            data: postData,
            method: 'GET',
            complete(res) {
              console.log(res)
              if (res.code === 200) {
                self.openid = res.data.openid
                self.session_key = res.data.session_key
              } else {
                uni.showToast({
                  title: res.message,
                  icon: 'none'
                });
              }
            }
          });
        }
      });
    },
    toAuthAndLogin(res) {
      this.phone_encryptedData = res.detail.encryptedData //用于解密
      this.phone_iv = res.detail.iv // 用于解密
      console.log(res, "获取手机号需要的参数");
      let pc = new WXBizDataCrypt('wxc53213d65b626fb5', this.session_key);
      let data = pc.decryptData(this.phone_encryptedData, this.phone_iv);
      console.log(data);
      if (data.phoneNumber != '') {
        this.phone = data.phoneNumber
      }
      // //得到手机号后去登录
      this.phoneLogin(this.phone, this.openid, null)
    },
    loginUseOtherPhone() {
      const self = this;
      if (!self.isAgree) {
        uni.showToast({
          title: self.i18nLogin['请阅读并同意用户协议'],
          icon: "none"
        });
      } else {
        self.showGetOtherPhone = true;
        self.showPhoneLogin = false
        self.formGetOtherPhone.phone = ""
        self.formGetOtherPhone.sms = ""
        self.$nextTick(() => {
          self.$refs.phoneCodeRef.resetZero()
          self.$refs.uFormPhoneLogin.setRules(this.rulesPhoneLogin);
        })
      }


    },
    toLoginWithOtherPhone() {
      this.$refs.uFormPhoneLogin.validate(valid => {
        if (valid) {
          //先去验证短信验证码
          this.veritySmsCode()
        } else {
          console.log('验证失败');
        }
      });
      this.showGetOtherPhone = true
    },
    veritySmsCode() {
      let postData = {
        "phone": self.formGetOtherPhone.phone,
        "code": self.formGetOtherPhone.sms,
      }
      //授权成功后拿openid和电话去登录
      $.ajax({
        url: commonAPI.veritySmsCode,
        data: postData,
        method: 'POST',
        complete(res) {
          if (res.code === 200) {
            self.toAuth(self.formGetOtherPhone.phone)
          } else {
            uni.showToast({
              title: res.message,
              icon: 'none'
            });
          }
        }
      });
    },
    toAuth(phone) {
      const self = this;
      // 去wx auth认证
      $.getToken().then(res => {
        if (res.errMsg == 'request:ok') {
          switch (res.data.code) {
            case 200:
              let data = res.data.data;
              let openid = data.openid
              let unionid = data.unionid;
              let session_key = data.session_key;
              self.getPhoneNumber(phone, openid, unionid, session_key)
              return
            case 500:
              uni.showToast({
                title: res.data.message,
                icon: 'none'
              });
          }
        }
      });
    },
    getPhoneNumber(phone, openid, unionid) {
      const self = this;
      self.username = phone
      if (self.username && typeof self.username !== 'undefined') {
        self.phoneLogin(self.username, openid, unionid)
      }
    },
    phoneLogin(phone, openid, unionid) {
      let postData = {
        "phone": phone,
        "openId": openid,
        "inviteCode": "8912058",
        "unionid": unionid
      }
      //授权成功后拿openid和电话去登录
      $.ajax({
        url: apiUrl.phoneLogin,
        data: postData,
        method: 'POST',
        loading: true,
        complete(res) {
          if (res.data && res.data.token) {
            uni.setStorageSync('token', res.data.tokenHead + ' ' + res.data.token);
            uni.showToast({
              title: '登录成功',
              icon: 'none'
            });

            self.getUserInfo();
            self.$refs.userTrendsDownload.init()
            self.showPhoneLogin = false
            self.showGetOtherPhone = false
          } else {
            uni.showToast({
              title: res.message,
              icon: 'none'
            });


          }
        }
      });
    },
    getPhoneClick() {
      const self = this;
      if (!self.isAgree) {
        uni.showToast({
          title: self.i18nLogin['请阅读并同意用户协议'],
          icon: "none"
        });
        return false;
      }
    },


    cancel() {
      this.showUpdateNickname = false
    },
    go,
    rejectLogin() {
      this.showPhoneLogin = false
    },
    updateUserInfo() {
      const self = this;
      $.ajax({
        url: 'member/updateMemberById',
        data: {
          "memberId": self.user.id,
          "nickname": self.nicknameUpdate,
        },
        method: 'POST',
        success(res) {
        },
        complete(data) {

        }
      })
      self.user.nickname = self.nicknameUpdate
      self.showUpdateNickname = false
    },
    updateNickname() {
      /*#ifdef H5*/
      this.nicknameUpdate = ""
      this.showUpdateNickname = true
      /*#endif*/

      /*#ifdef MP*/
      this.$refs.updateHeadNickname.init()
      // #endif
    },
    userIndexRefresh(data) {
      self = this;
      if (data.avatarUrl) {
        self.user.headImg = data.avatarUrl;
      }
      if (data.nickname) {
        self.user.nickname = data.nickname;
      }
      uni.setStorageSync('userInfo', self.user);

    },
    updateAuthStatus() {
      const self = this;
      self.isShowMerchantAuthentication = false
      self.isShowSuccessAuth = true
    },
    gotToDownloadNumApply() {
      let user = uni.getStorageSync('userInfo')
      if (!user.shopId) {
        self.$toast("请先认证关联商家");
      } else {
        this.$refs.toDownloadApplyModal.init();
      }

    },
    checkMyAuthInfo() {

      if (!uni.getStorageSync('userInfo').shopStatus || uni.getStorageSync('userInfo').shopStatus === 0) {
        this.$toast("请先认证关联商家");
        return
      }

      this.invitMsg = "商家邀请码："
      this.currentDoAuth = 'edit'

      this.isDisabled = true


      this.shopAuthForm.invitationCode = uni.getStorageSync('userInfo').authFromInvitCode
      this.shopAuthForm.bindShop = uni.getStorageSync('userInfo').authShop
      this.shopAuthForm.authDate = uni.getStorageSync('userInfo').authDate

      this.$nextTick(() => {
        this.$refs.toUserAuth.init(this.shopAuthForm.invitationCode, this.shopAuthForm.authDate, this.shopAuthForm.bindShop)
      })
    },


    openAssociationShopInfo() {
      this.getAssociationShopInfo()
    },
    getAssociationShopInfo() {
      const self = this;
      $.ajax({
        url: API.getUserShopById,
        data: {},
        method: 'GET',
        success(res) {
          self.associationShopForm = res.data
          self.showAssociationShopInfo = true
        }
      })
    },


    openAuthShop() {
      this.$refs.toUserAuth.init()
      this.isDisabled = false
      this.invitMsg = "请输入商家邀请码"
      this.currentDoAuth = 'add'
    },
    centerOrderList() {
      const self = this;
      $.ajax({
        url: API.centerOrderList,
        data: {},
        isAuth: true,
        method: 'GET',
        success(res) {
          self.orderList = res.data ? res.data : [];
          self.now = res.now;
        }
      })
    },
    updateImg() {
      let self = this
      /*#ifdef H5*/
      $.uploadimg({
        url: API.updateHeadImgApi,
        success(res) {
          self.user.headImg = res;

          uni.setStorageSync('userInfo', self.user);
        }
      })
      /*#endif*/

      /*#ifdef MP*/
      this.$refs.updateHeadNickname.init()
      // #endif


    },
    getAccount() {
      $.ajax({
        url: API.getAccountApi,
        data: {},
        isAuth: true,
        method: 'GET',
        success(res) {
          self.account = res.data ? res.data : '';
          uni.stopPullDownRefresh();
        }
      })
    },
    getUserInfo() {
      $.ajax({
        url: API.getUserApi,
        data: {},
        isAuth: true,
        method: 'GET',
        success(res) {
          self.user = res.data;
          if (self.user) {
            uni.setStorageSync('userInfo', self.user);
            if (self.user.shopStatus !== 1 && uni.getStorageSync('token')) {
              //如果登录了并且没认证
              self.isShowMerchantAuthentication = true;
              self.isShowSuccessAuth = false;
            } else if (self.user.shopStatus === 1 && uni.getStorageSync('token')) {
              //如果登录了并且认证了
              self.isShowMerchantAuthentication = false;
              self.isShowSuccessAuth = true;
            } else {
              self.isShowMerchantAuthentication = false;
              self.isShowSuccessAuth = false;
            }
          } else {
            self.user = ''
            self.isShowMerchantAuthentication = false;
            self.isShowSuccessAuth = false;
          }


        }
      })
    },
    getList() {
      $.ajax({
        url: shopsAPI.likeListApi,
        isAuth: true,
        data: {
          page: 1,
          pageSize: 20
        },
        method: 'GET',
        success(res) {
          self.list = res.data.list ? res.data.list : [];
        }
      })
    },
    getOrderNum() {
      $.ajax({
        url: API.getOrderNum,
        data: {},
        isAuth: true,
        method: 'GET',
        success(res) {
          self.order = res.data ? res.data : '';
          uni.stopPullDownRefresh();
        }
      })
    },
    init() {

    },
  },
  created() {
  },
  computed: {
    bgImage() {
      return 'url('+this.style['user_center_nav_background']+')'
    },
    i18n() {
      return this.$t('user')
    },
    i18nLogin() {
      return this.$t('login')
    },
  },
  mounted() {
  },
  destroyed() {
  },
  components: {updateHeadNickname, userTrendsDownload, toDownloadApplyModal, toUserAuth, phoneCode},
  onPullDownRefresh() {
    this.loadData()
  },
  onReachBottom() {
  }
}
</script>
